#ifndef SHARE_H
#define SHARE_H

#include <windows.h>

#define RT_BIT(bit) (1U << (bit))
#define MAX_BUF_SIZE RT_BIT(19)
#define SHARE_SIGNATURE 0xFDB98ACE

#define TERM_TIMEOUT              1000 // "ms"

#define VIRTIOFSD_TEMP_PATH "\\\\HwFs"
#define HWFS_CLIPBOARD_SHARES_PREFIX L"\\\\HwFs\\clipboard_"

// Maximum size of plain text.
#define PLAIN_TEXT_SIZE_MAX (20 * 1024 * 1024)
// Maximum size of bitmap.
#define BITMAP_SIZE_MAX (128 * 1024 * 1024)
// Maximum size of HTML data.
#define HTML_SIZE_MAX (20 * 1024 * 1024)
// Maximum number of HTML files.
#define HTML_FILES_MAX 100
// Maximum size of a single HTML file.
#define HTML_FILE_SIZE_MAX (128 * 1024 * 1024)

#define THROW_ERR(err) throw((DWORD)(err))

/** Do *not* change the name, as this will break compatbility with other (legacy) applications! */
#define CBSH_WIN_REGFMT_HTML     L"HTML Format"

#define HTML_URI_REGEX           R"((src="file:///)(.*?)(\\|/)([^\\"/]*["]))"
#define HTML_FILE_PATH_REGEX     R"r(src="file:///(.*?)["'])r"
#define FILE_NAME_REGEX          R"(.+[\\/](.+)$)"

#define HWFS_FILE_SYSTEM_NAME    L"HwFs"
#define UNC_ROOT_DIR_W_REGEX     LR"(\\\\[^\\]+\\[^\\]+)"

/** No format set. */
#define CBSH_FMT_NONE               0
/** Clipboard Share format is bitmap (BMP / DIB). */
#define CBSH_FMT_BITMAP             RT_BIT(0)
/** Clipboard Share format is a transfer list. */
#define CBSH_FMT_URI_LIST           RT_BIT(1)
/** Clipboard Share format is an Unicode text. */
#define CBSH_FMT_UNICODETEXT        RT_BIT(2)
/** Clipboard Share format is HTML Format. */
#define CBSH_FMT_HTML               RT_BIT(3)
/** Clipboard Share window is ready. */
#define CBSH_READY                  RT_BIT(4)
/** Clipboard Sharing File Sharing Finished. */
#define CBSH_FILES_FINISH           RT_BIT(5)
/** Clipboard Sharing HTML Files Virtual Share. */
#define CBSH_HTML_FILES_VIRT_SHARE  RT_BIT(6)
/** Sync Clipboard data to Host. */
#define CBSH_SYNC_DATA_TO_HOST      RT_BIT(7)
/** Clipboard Share formats in unicode and HTML. */
#define CBSH_UNICODE_AND_HTML  (CBSH_FMT_UNICODETEXT | CBSH_FMT_HTML)

#pragma pack (push, 1)
typedef struct {
    DWORD signature;
    DWORD crc;
    DWORD headerLen;
    DWORD format;
    SIZE_T dataLen;
} ShareHeader;
#pragma pack(pop)

typedef struct {
    SIZE_T utf8Len;
    SIZE_T htmlLen;
} TextHeader;

#endif // SHARE_H
